
var editIndex = undefined;// 正在编辑的行的索引
var deleteIndex = undefined;

// 结束正在被编辑的行，编辑之前先对组件进行验证
function endEditing() {
	if (editIndex == undefined) {
		return true
	}
	if ($('#edite_eplan_Details_tabs').datagrid('validateRow', editIndex)) { // 验证
		$('#edite_eplan_Details_tabs').datagrid('endEdit', editIndex);// 结束编辑
		editIndex = undefined;
		return true;// 验证通过
	} else {
		return false;// 验证不通过
	}
}

// 单击单元格的事件
function onClickCell(index/* 行索引 */, field/* json中的一个属性 */) {
	if (editIndex != index) {// 如果正在编辑的行与单击的单元格所在行不同
		if (endEditing()) {// 先将原来编辑的行结束
			$('#edite_eplan_Details_tabs').datagrid('selectRow', index)// 选择新行
			.datagrid('beginEdit', index);// 新行处于编辑状态
			var ed = $('#edite_eplan_Details_tabs').datagrid('getEditor', {
				index : index,
				field : field
			});// 获取单元格编辑器
			if (ed) {
				($(ed.target).data('textbox') ? $(ed.target).textbox('textbox')
						: $(ed.target)).focus();
			}
			editIndex = index;
		} else {
			setTimeout(function() {
				$('#edite_eplan_Details_tabs').datagrid('selectRow', editIndex);
			}, 0);
		}
	}
}

// 结束编辑
function onEndEdit(index, row) {
	/*
	 * var ed = $(this).datagrid('getEditor', { index: index, field: 'productid'
	 * //根据实际情况进行改动 }); row.productname = $(ed.target).combobox('getText');
	 */
}

function onSelect(index, row) {
	deleteIndex = index;
	if (editIndex != index) {
		$("#edite_eplan_Details_tabs").datagrid('validateRow', editIndex);
		$("#edite_eplan_Details_tabs").datagrid('endEdit', editIndex);// 结束编辑
	}
	editIndex = undefined;
}

//结束正在被编辑的行，编辑之前先对组件进行验证
function endEditingBus() {
	if (editIndex == undefined) {
		return true
	}
	if ($('#edite_buisness_people_tabs').datagrid('validateRow', editIndex)) { // 验证
		$('#edite_buisness_people_tabs').datagrid('endEdit', editIndex);// 结束编辑
		editIndex = undefined;
		return true;// 验证通过
	} else {
		return false;// 验证不通过
	}
}

// 单击单元格的事件
function onClickCellBus(index/* 行索引 */, field/* json中的一个属性 */) {
	if (editIndex != index) {// 如果正在编辑的行与单击的单元格所在行不同
		if (endEditingBus()) {// 先将原来编辑的行结束
			$('#edite_buisness_people_tabs').datagrid('selectRow', index)// 选择新行
			.datagrid('beginEdit', index);// 新行处于编辑状态
			var ed = $('#edite_buisness_people_tabs').datagrid('getEditor', {
				index : index,
				field : field
			});// 获取单元格编辑器
			if (ed) {
				($(ed.target).data('textbox') ? $(ed.target).textbox('textbox')
						: $(ed.target)).focus();
			}
			editIndex = index;
		} else {
			setTimeout(function() {
				$('#edite_buisness_people_tabs').datagrid('selectRow', editIndex);
			}, 0);
		}
	}
}


function onSelectBus(index, row) {
	deleteIndex = index;
	if (editIndex != index) {
		$('#edite_buisness_people_tabs').datagrid('validateRow', editIndex);
		$('#edite_buisness_people_tabs').datagrid('endEdit', editIndex);// 结束编辑
	}
	editIndex = undefined;
}


// 追加一行
function append() {
	if (endEditing()) {
		// 追加新行
		$('#equip_add_dg').datagrid('appendRow', {});
		// 返回最后一行的索引
		editIndex = $('#equip_add_dg').datagrid('getRows').length - 1;
		console.log(editIndex);
		// 选择最后一行，将最后一行变成编辑状态
		$('#equip_add_dg').datagrid('beginEdit', editIndex);
	}
}


//删除选中的行
function removeit(){
	var rows = $('#equip_add_dg').datagrid('getSelections');			
	//数据库删除成功则删除页面   再重新加载
	for(var i=0; i<rows.length; i++){
		var row = rows[i];
		var id = row.usid;
	
		//发送到数据库  删除
		/*$.get("deleteUsers?userid="+id ,function(result){
			
		});*/
		//删除页面
		var index=$('#equip_add_dg').datagrid('getRowIndex',row);
		$('#equip_add_dg').datagrid('deleteRow', index);
		}
		
	}


// 获取添加、修改和删除的所在json对象
function getChanges() {
	var inserted = $('#equip_add_dg').datagrid('getChanges', "inserted");
	var updated = $('#equip_add_dg').datagrid('getChanges', "updated");
	console.log(JSON.stringify(inserted));
	console.log(JSON.stringify(updated));
}

//自定义验证 
$(function(){
	  $.extend($.fn.validatebox.defaults.rules, {
          isBlank: {
              validator: function (value, param) { return $.trim(value) != '' },
              message: '不能为空，全空格也不行'
          }
      });
});
$(function() {
	$.extend($.fn.validatebox.defaults.rules, {
		gdp : {
			validator : function(value, param) {
				return /^\d{3,4}-\d{7,8}$/.test(value);
			},
			message : '固定电话号码格式不正确'
		}
	})
});
//添加采购订单页面
function appendESO(){
	var eosName=$("#eos_select_open").val();
	var eoscomany=$("#rdetail_comp").combobox('getValue');
	var eosNum=$("#rdetail_num").val();
	var eosType=$("#rdetail_type").val()
	if(eosName==""){
		$.messager.alert('警告','还没有选择设备、耗材','info');    
	}else if(eosNum==""){
		$.messager.alert('警告','数量为必填项','info');    
	}else{
	//追加
	$("#equip_add_dg").datagrid('appendRow',{
		edetailName3:eosName,
		edetailNum:eosNum,
		edetailUnit:eoscomany,
		edetailType:eosType
	});
	//清除数据
	$("#eos_select_open").textbox('setValue','');
	$("#rdetail_comp").combobox('setValue','');
	$("#rdetail_num").textbox('setValue','');
	$("#rdetail_type").textbox('setValue','');
	}
}


//添加外包商
function appendBus(){
	var buspoName=$("#buspo_name").val();
	var buspoPhone=$("#buspo_phone").val();
	var buspoEmil=$("#buspo_emil").val()
	if(buspoName==""){
		$.messager.alert('警告','姓名不能为空','info');    
	}else if(buspoPhone==""){
		$.messager.alert('警告','电话不能为空','info');    
	}else if(buspoEmil==""){
		$.messager.alert('警告','邮箱不能为空','info');    
	}else{
	//追加
	$("#bus_add_dg").datagrid('appendRow',{
		bpeoName:buspoName,
		bpeoPhone:buspoPhone,
		bpeoEmil:buspoEmil
	});
	/*//清除数据
	$("#buspo_name").textbox('setValue','');
	$("#buspo_phone").textbox('setValue','');
	$("#buspo_emil").textbox('setValue','');*/
	}
}
function removeitBus(){
	var rows = $('#bus_add_dg').datagrid('getSelections');			
	for(var i=0; i<rows.length; i++){
		var row = rows[i];
		var id = row.usid;
		//删除页面
		var index=$('#bus_add_dg').datagrid('getRowIndex',row);
		$('#bus_add_dg').datagrid('deleteRow', index);		
	}
}	
function appendBusEdite(){
	var buspoName=$("#edite_buspo_name").val();
	var buspoPhone=$("#edite_buspo_phone").val();
	var buspoEmil=$("#edite_buspo_emil").val()
	if(buspoName==""){
		$.messager.alert('警告','姓名不能为空','info');    
	}else if(buspoPhone==""){
		$.messager.alert('警告','电话不能为空','info');    
	}else if(buspoEmil==""){
		$.messager.alert('警告','邮箱不能为空','info');    
	}else{
	//追加
	$("#edite_buisness_people_tabs").datagrid('appendRow',{
		bpeoName:buspoName,
		bpeoPhone:buspoPhone,
		bpeoEmil:buspoEmil
	});
	//清除数据
	$("#edite_buspo_name").textbox('setValue','');
	$("#edite_buspo_phone").textbox('setValue','');
	$("#edite_buspo_emil").textbox('setValue','');
	}
}
function removeitBusEdite(){
	var rows = $('#edite_buisness_people_tabs').datagrid('getSelections');			
	for(var i=0; i<rows.length; i++){
		var row = rows[i];
		//删除页面
		var index=$('#edite_buisness_people_tabs').datagrid('getRowIndex',row);
		$('#edite_buisness_people_tabs').datagrid('deleteRow', index);		
	}
}	

function onclickYes(){
	var row = $("#select_eos").datagrid('getSelected');
	var name= row.name;
	var company = row.company;
	var type = row.type;
	$("#rdetail_type").textbox('setValue',type);
	$("#eos_select_open").textbox('setValue',name);
	$("#rdetail_comp").combobox('setValue',company);
	$("#eqOfficeSuppl_select").window("close");
}
var buttonArea = function(value, row, index) {
	var btn1 = "<input onclick='LookEplan(" +index
			+ ")'  class='plan_in_btn' type='button' value='查看'>";
	var btn2 = "<input onclick='EditeEplan(" +index
			+ ")' class='plan_in_btn' type='button' value='编辑'>";
	var btn3 = "<input onclick='DeletedEplan(" + index
			+ ")' class='plan_in_btn' type='button' value='删除'>";
	var btn4 = "<input onclick='CheckedEplan(" + index
			+ ")' class='plan_in_btn' type='button' value='审核'>";
	return btn1 + btn2 + btn3 + btn4;
}
function PlanbuttonAreaInit(){
	var rows=$("#equip_plan_list").datagrid('getRows');
	for(var i=0;i<rows.length;i++){
		
		if(row.eplanState.equals("已审核")){
			$("#edite_Equiplan").attr("disabled", true); 
			$("#deleted_Equiplan").attr("disabled", true); 
		}else if(row.eplanState.equals("已订购")){
			$("#edite_Equiplan").attr("disabled", true); 
			$("#deleted_Equiplan").attr("disabled", true); 
			$("#checked_Equiplan").attr("disabled", true); 
		}
	}
}
var DeletedEplan = function(index) {
	$("#equip_plan_list").datagrid('selectRow',index);
	var rows=$("#equip_plan_list").datagrid('getSelected');
	var eplanId=rows.eplanId;
	if(rows.eplanState=="已审核"){
		$.messager.alert("删除", "该计划已通过审核，不可删除！")
	}else if(rows.eplanState=="已订购"){
		$.messager.alert("删除", "该计划已订购，不可删除！")
	}else{
		$.messager.confirm("删除", "确认要删除该计划吗？", function(v) {
			if (v) {
				$.post("delete_eplan", {
					eplanId : eplanId
				}, function(v) {
					$("#equip_plan_list").datagrid("load");
				});
			}
		});	
	}	
}
var CheckedEplan=function(index){
	$("#equip_plan_list").datagrid('selectRow',index);
	var rows=$("#equip_plan_list").datagrid('getSelected');
	var eplanId=rows.eplanId;
	if(rows.eplanState=="已审核"){
		$.messager.alert("审核", "该计划已通过审核，不可再次审核！")
	}else if(rows.eplanState=="已订购"){
		$.messager.alert("审核", "该计划已订购，不可再次审核！")
	}else{
		$.messager.confirm("审核", "确认要通过该计划吗？", function(v) {
			if (v) {
				$.post("checked_Eplan", {
					eplanId : eplanId
				}, function(v) {
					$("#equip_plan_list").datagrid("load");
				});
			}
		});
	}
	
	
	
}
function equiplanWhere() {
	var eplanType = $("#eplanType").combobox('getValue');
	var eplanDate = $("#eplanDate").datebox('getValue');
	var eplanTitle = $("#eplanTitle").val();
	var eplanAuthor = $("#eplanAuthor").val();
	$("#equip_plan_list").datagrid(
			'load',
			'get_equiplanWhere?eplanType=' + eplanType + '&eplanDate='
					+ eplanDate + '&eplanTitle=' + eplanTitle
					+ '&eplanAuthor=' + eplanAuthor);
	$("#eplanType").combobox('setValue', '');
	$("#eplanDate").datebox('setValue', '');
	$("#eplanTitle").textbox('setValue', '');
	$("#eplanAuthor").textbox('setValue', '');
}

var LookEplan = function(index) {
	$("#eplan_select_detail").window("open");
	
	$("#equip_plan_list").datagrid('selectRow',index);
	var rows=$("#equip_plan_list").datagrid('getSelected');
	
	$("#eplan_Title").textbox('setValue',rows.eplanTitle);
	$("#eplan_Author").textbox('setValue',rows.eplanAuthor);
	$("#eplan_Type").textbox('setValue',rows.eplanType);
	$("#eplan_Date").textbox('setValue',rows.eplanDate);
	$("#eplan_Dept").textbox('setValue',rows.eplanDept);
	
	$("#eplan_Details_tabs").datagrid({
		url:'get_EplanOneDetail',
		queryParams:{
			"eplan_id":rows.eplanId
		}
	});
}


var EditeEplan= function(index){
	$("#equip_plan_list").datagrid('selectRow',index);
	var rows=$("#equip_plan_list").datagrid('getSelected');
	if(rows.eplanState=="已审核"){
		$.messager.alert("编辑", "该计划已通过审核，不可编辑！")
	}else if(rows.eplanState=="已订购"){
		$.messager.alert("编辑", "该计划已订购，不可编辑！")
	}else{
		$("#edite_eplan_Id").val(rows.eplanId);
		$("#edite_eplan_Title").textbox('setValue',rows.eplanTitle);
		$("#edite_eplan_Author").textbox('setValue',rows.eplanAuthor);
		$("#edite_eplan_Type").combobox('setValue',rows.eplanType);
		$("#edite_eplan_Date").datebox('setValue',rows.eplanDate);
		$("#edite_eplan_Dept").combotree('setValue',rows.eplanDept);
		
		$("#edite_eplan_Details_tabs").datagrid({
			url:'get_EplanOneDetail',
			queryParams:{
				"eplan_id":rows.eplanId
			}
		});
		
		$("#eplan_edite_detail").window("open");
	}
	
}

//编辑采购订单页面
function appendEdietSO(){
	var eosName=$("#eos_selectEdite_open").val();
	var eoscomany=$("#edite_rdetail_comp").combobox('getValue');
	var eosNum=$("#edite_rdetail_num").val();
	var eosType=$("#edite_rdetail_type").val()
	if(eosName==""){
		$.messager.alert('警告','还没有选择设备、耗材','info');    
	}else if(eosNum==""){
		$.messager.alert('警告','数量为必填项','info');    
	}else{
	//追加
	$("#edite_eplan_Details_tabs").datagrid('appendRow',{
		edetailName3:eosName,
		edetailNum:eosNum,
		edetailUnit:eoscomany,
		edetailType:eosType
	});
	//清除数据
	$("#eos_selectEdite_open").textbox('setValue','');
	$("#edite_rdetail_comp").combobox('setValue','');
	$("#edite_rdetail_num").textbox('setValue','');
	$("#edite_rdetail_type").textbox('setValue','');
	}
}
//删除选中的行
function removeitEdietSO(){
	var rows = $('#edite_eplan_Details_tabs').datagrid('getSelections');			
	//数据库删除成功则删除页面   再重新加载
	for(var i=0; i<rows.length; i++){
		var row = rows[i];
		//删除页面
		var index=$('#edite_eplan_Details_tabs').datagrid('getRowIndex',row);
		$('#edite_eplan_Details_tabs').datagrid('deleteRow', index);
		}		
	}

var BusButtonArea= function(value ,row ,index){
	var btn1 = "<input onclick='LookBusiness(" +index
	+ ")'  class='plan_in_btn' type='button' value='查看'>";
	var btn2 = "<input onclick='EditeBusiness(" +index
	+ ")' class='plan_in_btn' type='button' value='编辑'>";
	var btn3 = "<input onclick='DeletedBus(" + row.busId
	+ ")' class='plan_in_btn' type='button' value='删除'>";
	return btn1+btn2+btn3;
}

var DeletedBus = function(busId) {
	$.messager.confirm("删除", "确认要删除该外商吗？", function(v) {
		if (v) {
			$.post("delete_business", {
				busId : busId
			}, function(v) {
				$("#business_list_tabs").datagrid("load");
			});
		}
	});
}
function businessWhere() {
	var busType = $("#busType").combobox('getValue');
	var busName = $("#busName").val();
	var busAddress = $("#busAddress").val();
	$("#business_list_tabs").datagrid(
			'load',
			'get_BusinessWhere?busType=' + busType + '&busName='
					+ busName + '&busAddress=' + busAddress);
	
	$("#busType").combobox('setValue', '');
	$("#busName").textbox('setValue', '');
	$("#busAddress").textbox('setValue', '');
}

var LookBusiness = function(index) {	
	$("#business_list_tabs").datagrid('selectRow',index);
	var rows=$("#business_list_tabs").datagrid('getSelected');
	$("#bus_name").textbox('setValue',rows.busName);
	$("#bus_phone").textbox('setValue',rows.busPhone);
	$("#bus_type").textbox('setValue',rows.busType);
	$("#bus_address").textbox('setValue',rows.busAddress);
	
	$("#business_people_tabs").datagrid({
		url:'get_BusinessOnePeople',
		queryParams:{
			"businessId":rows.busId
		}
	});
	$("#business_select_people").window("open");	
}

var EditeBusiness= function(index){
	$("#business_list_tabs").datagrid('selectRow',index);
	var rows=$("#business_list_tabs").datagrid('getSelected');
	$("#edite_bus_id").val(rows.busId);
	$("#edite_bus_name").textbox('setValue',rows.busName);
	$("#edite_bus_phone").textbox('setValue',rows.busPhone);
	$("#edite_bus_type").combobox('setValue',rows.busType);
	$("#edite_bus_address").textbox('setValue',rows.busAddress);
	
	$("#edite_buisness_people_tabs").datagrid({
		url:'get_BusinessOnePeople',
		queryParams:{
			"businessId":rows.busId
		}
	});
	$("#business_edite_people").window("open");
}
function createEquipOrderId(){
	$.getJSON('to_EquipOrderId',{},function(v){
		$("#EquipOrderId").textbox("setValue",v);
	});
}

function createStorageId(){
	$.getJSON('to_equipStorageId',{},function(v){
		$("#EquipOrderSaveId").textbox("setValue",v);
	});
}
 function selectCheckedEplan(index, row){
	$("#CheckedEplan_list_tabs").datagrid('selectRow',index);
	var rows=$("#CheckedEplan_list_tabs").datagrid('getSelected');
	$("#checkedEplan_select_open").textbox('setValue',rows.eplanTitle);
	$("#checked_eplanDept").textbox('setValue',rows.eplanDept);
	$("#checked_eplanAuthor").textbox('setValue',rows.eplanAuthor);
	$("#checked_eplanId").textbox('setValue',rows.eplanId);
	$("#order_equip_detail_tabs").datagrid({
		url:'get_EplanOneDetail',
		queryParams:{
			"eplan_id":rows.eplanId
		}
	});
	$("#checkedEplan_select").window("close");
 }
 
 function selectSupplierBusiness(index, row){
	 $("#SupplierBusiness_list_tabs").datagrid('selectRow',index);
	var rows=$("#SupplierBusiness_list_tabs").datagrid('getSelected');
	$("#supplier_select_open").textbox('setValue',rows.busName);
	$("#supplier_select_Id").textbox('setValue',rows.busId);
	$("#order_bus_name").textbox('setValue',rows.busName);
	$("#order_bus_phone").textbox('setValue',rows.busPhone);
	$("#order_bus_type").textbox('setValue',rows.busType);
	$("#order_bus_address").textbox('setValue',rows.busAddress);
	
	$("#order_business_people_tabs").datagrid({
		url:'get_BusinessOnePeople',
		queryParams:{
			"businessId":rows.busId
		}
	});
	$("#supplier_select").window("close");
 }
 
 function SelectEditeESO(index, row){
	 $("#edite_select_eos").datagrid('selectRow',index);
	var rows=$("#edite_select_eos").datagrid('getSelected');
	$("#eos_selectEdite_open").textbox('setValue',rows.name);
	$("#edite_rdetail_comp").textbox('setValue',rows.company);
	$("#edite_rdetail_type").textbox('setValue',rows.type);
	
	$("#edOfficeSuppl_select").window("close");
 }
 
 function getBuyEplanOrder(index, row){
	 $("#BuyEplanOrder_list_tabs").datagrid('selectRow',index);
	var rows=$("#BuyEplanOrder_list_tabs").datagrid('getSelected');
	$("#eplanOrder_select_open").textbox('setValue',rows.eorderId);
	$("#eplanOrder_cgName").textbox('setValue',rows.eorderName);
	$("#eplanOrder_gBusiness").textbox('setValue',rows.busOrdername);
	
	$("#Equip_Order_Details_tabs").datagrid({
		url:'get_EplanOneDetail',
		queryParams:{
			"eplan_id":rows.equipPlan.eplanId
		}
	});
	$("#checkEplanOrder_select").window("close");
 }
 

 
 function getOneDoctorRegistration(){
	 var doctorID="14";
	 $("#get_OneDoctorReg_peo").datagrid({
			url:'get_OneDoctorRegistration',
			queryParams:{
				"doctorID":doctorID
			}
		});
 }
 
 function doctorPatientReg(index,row){
	 $('#receive_patient_treatment_cardnum').textbox('setValue',
			row.PATIENT_REGISTRATION_ID);
	$('#receive_patient_treatment_name').textbox('setValue', row.NAME);
	$('#receive_patient_treatment_sex').textbox('setValue', row.SEX);
	$('#receive_patient_treatment_age').textbox('setValue', row.AGE);
	$('#receive_patient_treatment_adress').textbox('setValue', row.ADDRESS);
	var PATIENT_REGISTRATION_ID=row.PATIENT_REGISTRATION_ID;
	
	$.post("update_Registration",{
		patient_reg_id:PATIENT_REGISTRATION_ID
	},function(v){
		$("#PATIENT_REGISTRATION_tabs").datagrid("load");
	});
	
 }
 
 function clearaddEquipStoSave(){
	 $("#save_equipOrder_name").textbox('setValue','');
		$("#save_equipOrder_num").numberbox('setValue','');
		$("#save_equipOrder_Mdate").datebox('setValue','');
		$("#save_equipOrder_Edate").datebox('setValue','');
		$("#save_equipOrder_remarkers").textbox('setValue','');
		$("#save_equipOrder_type").textbox('setValue','');
 }
function addEquipStoSave(index,field, value){
	clearaddEquipStoSave();
	$("#Equip_Order_Details_tabs").datagrid('selectRow',index);
	var row = $("#Equip_Order_Details_tabs").datagrid('getSelected');
	$("#save_equipOrder_name").textbox('setValue',row.edetailName3);
	$("#save_equipOrder_num").numberbox('setValue',row.edetailNum);
	$("#save_equipOrder_company").textbox('setValue',row.edetailUnit);
	$("#save_equipOrder_type").textbox('setValue',row.edetailType);

	$("#Equip_Order_Details_tabs").datagrid('deleteRow',index);
	/*设置的状态
	var rows = $("Equip_Order_Details_tabs").datagrid('getRows');
	if(rows.length==0){
		var eplanOrder_select_Id=$("#eplanOrder_select_open").textbox('getValue');
		$.post("set_OrderSaveState",{
			eplanOrder_Id:eplanOrder_select_Id
		},function(v){
			$("#BuyEplanOrder_list_tabs").datagrid('load');
		});
	}*/
}

function appendESOSave(){
	var Name=$("#save_equipOrder_name").val();
	var Num=$("#save_equipOrder_num").numberbox('getValue');
	var Mdate=$("#save_equipOrder_Mdate").datebox('getValue');
	var Edate =$("#save_equipOrder_Edate").datebox('getValue');	
	var remarkers=$("#save_equipOrder_remarkers").textbox('getValue');
	var comUnit=$("#save_equipOrder_company").textbox('getValue');
	var Type=$("#save_equipOrder_type").textbox('getValue');
	if(Name==""){
		$.messager.alert('警告','还没有选择设备、耗材','info');    
	}else if(Num==""){
		$.messager.alert('警告','数量为必填项','info');    
	}else{
	//追加
	$("#save_equip_SOE").datagrid('appendRow',{
		sdetailName:Name,
		sdetailNum:Num,
		sdetailutil:comUnit,
		sdetailMdate:Mdate,
		sdetailEdate:Edate,
		sdetailRemarks:remarkers,
		sdetailtype:Type
	});
	clearaddEquipStoSave();
	//清除数据
	
	}
}

function equipStroageSaveWhere() {
	var equipsaveBatchId = $("#equipsaveBatch_id").textbox('getValue');
	var equipsaveBatchName = $("#equipsaveBatch_name").textbox('getValue');
	var equipsaveBatchEdate = $("#equipsaveBatch_edate").datebox('getValue');
	
	$("#equipsave_list_tabs").datagrid(
			'load',
			'get_equipStroageSaveWhere?equipsaveBatchId=' + equipsaveBatchId + '&equipsaveBatchName='
					+ equipsaveBatchName + '&equipsaveBatchEdate=' + equipsaveBatchEdate);
				
	$("#equipsaveBatch_id").textbox('setValue', '');
	$("#equipsaveBatch_name").textbox('setValue', '');
	$("#equipsaveBatch_edate").datebox('setValue', '');
}

var equipsaveButton = function(value, row, index) {	
	var btn1 = "<input onclick='AbleUse(" +index
		+ ")' class='plan_in_btn' type='button' value='解禁'>";
	var btn2 = "<input onclick='MoveOut(" +index
			+ ")' class='plan_in_btn' type='button' value='移除'>";
	var btn3 = "<input onclick='Disable(" +index
	+ ")' class='plan_in_btn' type='button' value='禁用'>";
	return  btn1 + btn2 + btn3;
}

var Disable = function (index){
	$("#equipsave_list_tabs").datagrid('selectRow',index);
	var row = $("#equipsave_list_tabs").datagrid('getSelected');
	if(row.equipsaveState=="禁用"){
		$.messager.alert("禁用","该库存已经处于禁用状态！");
	}else{
		$.messager.confirm("禁用","确认要禁用该库存吗？",function (v){
			$.post("set_EquipSaveState",{
				equipsaveid:row.equipsaveid
			},function(s){
				$("#equipsave_list_tabs").datagrid('load');
			});
		});
	}		
}
var AbleUse = function (index){
	$("#equipsave_list_tabs").datagrid('selectRow',index);
	var row = $("#equipsave_list_tabs").datagrid('getSelected');
	if(row.equipsaveState=="正常"){
		$.messager.alert("解禁","该库存已经处于可用状态！");
	}else{
		$.messager.confirm("解禁","确认要恢复该库存使用吗？",function (v){
			$.post("set_EquipSaveStateOk",{
				equipsaveid:row.equipsaveid
			},function(s){
				$("#equipsave_list_tabs").datagrid('load');
			});
		});
	}
}
var MoveOut= function (index){
	$("#equipsave_list_tabs").datagrid('selectRow',index);
	var row = $("#equipsave_list_tabs").datagrid('getSelected');
	if(row.equipsaveState=="正常"){
		$.messager.alert("移除","库存正常不可移除！");
	}else{
		$.messager.confirm("清除库存", "确认要清除该库存吗？", function(v) {
			if (v) {
				$.post("set_EquipSaveMove",{
					equipsaveid:row.equipsaveid
				},function(s){
					$("#equipsave_list_tabs").datagrid('load');
				});
			}
		});
	}
	
	
}
function OpenEquipSaveList(){
	$("#equipsave_list_tabs").datagrid({   
    rowStyler:function(index,row){   
        if (row.equipsaveState=="禁用"){   
            return 'background-color:#FF7256';   
        }   
    }
});	
}

function EquipReturnId(){
	$.getJSON("to_EquipReturnId",{},function(v){
		$("#EquipReturnId").textbox("setValue",v);
	});	
}
function getUnableESOlist(index){
	$("#unableESO_list_dg").datagrid('selectRow',index);
	var row = $("#unableESO_list_dg").datagrid('getSelected');
	var eosRetrunName = row.equipsaveName;
	var eosRetrunNum = row.equipsaveNum;
	var eosRetrunCompany = row.equipsaveUntil;
	var businessName = row.equipsaveBusiness;
	var equipsaveid = row.equipsaveid;
	
	$("#eos_Return_open").textbox('setValue',eosRetrunName);
	$("#rdetail_num").numberbox('setValue',eosRetrunNum);
	$("#rdetail_company").textbox('setValue',eosRetrunCompany);
	$("#business_name").textbox('setValue',businessName);
	$("#rdetail_equipsaveid").textbox('setValue',equipsaveid);
	
	/*if(row.businessName!=$("#business_name").textbox('getValue')){
		$.messager.confirm("添加退货", "与该退货单的供应商不匹配！")
	}*/
	$("#eos_Retrun_select").window("close");
	$('#unableESO_list_dg').datagrid('deleteRow', index);	
}

//退货页面
function appendReturn() {	
	var retuanName=$("#eos_Return_open").val();
	var rdetailNum=$("#rdetail_num").val();
	var rdetailCmp=$("#rdetail_company").textbox('getValue');
	var rdetailReason=$("#rdetail_reason").val();
	var equipsaveid = $("#rdetail_equipsaveid").textbox('getValue');
		// 追加新行
		$('#order_return_dg').datagrid('appendRow', {
			rdetail_name:retuanName,
			rdetail_num:rdetailNum,
			rdetail_comp:rdetailCmp,
			rdetail_reason:rdetailReason,
			rdetail_equipsaveid:equipsaveid
		});	
	$("#eos_Return_open").textbox('setValue','');
	$("#rdetail_num").textbox('setValue','');
	$("#rdetail_company").textbox('setValue','');
	$("#rdetail_reason").textbox('setValue','');
	$("#rdetail_equipsaveid").textbox('setValue','');
}
function removeiReturn(){
	var rows = $('#order_return_dg').datagrid('getSelections');			
	for(var i=0; i<rows.length; i++){
		var row = rows[i];
		//删除页面
		var index=$('#order_return_dg').datagrid('getRowIndex',row);
		$('#order_return_dg').datagrid('deleteRow', index);		
	}
}
function initDeliveryId(){
	$.getJSON("to_DeliveryId",{},function(v){
		$("#deliveryId").textbox("setValue",v);
	});	
}

function getAbleESOlist(index){
	$("#ableESO_list_dg").datagrid('selectRow',index);
	var row = $("#ableESO_list_dg").datagrid('getSelected');
	var eosRetrunName = row.equipsaveName;
	var eosRetrunNum = row.equipsaveNum;
	var eosRetrunCompany = row.equipsaveUntil;
	var equipsaveid = row.equipsaveid;
	
	$("#eos_Delivery_open").textbox('setValue',eosRetrunName);
	$("#delivery_num").numberbox('setValue',eosRetrunNum);
	$("#delivery_company").textbox('setValue',eosRetrunCompany);
	$("#delivery_equipsaveid").textbox('setValue',equipsaveid);
	
	$("#eos_Delivery_select").window("close");
	/*$('#ableESO_list_dg').datagrid('deleteRow', index);	*/
}
function appendDelivery(){
	var retuanName=$("#eos_Delivery_open").val();
	var rdetailNum=$("#delivery_realNum").val();
	var rdetailCmp=$("#delivery_company").textbox('getValue');
	var rdetailReason=$("#delivery_reason").val();
	var equipsaveid = $("#delivery_equipsaveid").textbox('getValue');
	var knum = $("#delivery_num").val();
	if(retuanName==""){
		$.messager.alert("操作提示", "还没有选择领用设备器材！");
	}else if(rdetailNum==""){
		$.messager.alert("操作提示", "没有填入领取数量！");
	}else if((knum-0)<(rdetailNum-0)){
		$.messager.alert("操作提示", "数量超过库存量！");
	}else{
		$("#order_delivery_dg").datagrid('appendRow', {
			rdetail_name:retuanName,
			rdetail_num:rdetailNum,
			rdetail_comp:rdetailCmp,
			rdetail_reason:rdetailReason,
			rdetail_equipsaveid:equipsaveid
		});	
		$("#eos_Delivery_open").textbox('setValue','');
		$("#delivery_realNum").numberbox('setValue','');
		$("#delivery_company").textbox('setValue','');
		$("#delivery_equipsaveid").textbox('setValue','');	
		$("#delivery_reason").textbox('setValue','');	
	}
		
}
function removeiDelivery(){
	var rows = $('#order_delivery_dg').datagrid('getSelections');			
	for(var i=0; i<rows.length; i++){
		var row = rows[i];
		//删除页面
		var index=$('#order_delivery_dg').datagrid('getRowIndex',row);
		$('#order_delivery_dg').datagrid('deleteRow', index);		
	}
}

function orderSaveBusinessWhere() {
	var busType = $("#orderSave_busType").combobox('getValue');
	var busName = $("#orderSave_busName").val();
	var busAddress = $("#orderSave_busAddress").val();
	$("#SupplierBusiness_list_tabs").datagrid(
			'load',
			'get_BusinessWhere?busType=' + busType + '&busName='
					+ busName + '&busAddress=' + busAddress);
	
	$("#orderSave_busType").combobox('setValue', '');
	$("#orderSave_busName").textbox('setValue', '');
	$("#orderSave_busAddress").textbox('setValue', '');
}

function orderSaveEquiplanWhere() {
	var eplanType = $("#orderSave_eplanType").combobox('getValue');
	var eplanDate = $("#orderSave_eplanDate").datebox('getValue');
	var eplanDept = $("#orderSave_eplanDept").combotree('getValue');
	$("#CheckedEplan_list_tabs").datagrid(
			'load',
			'get_CheckedEplanWhere?eplanType=' + eplanType + '&eplanDate='
					+ eplanDate + '&eplanDept=' + eplanDept);
					
	$("#orderSave_eplanType").combobox('setValue', '');
	$("#orderSave_eplanDate").datebox('setValue', '');
	$("#orderSave_eplanDept").combotree('setValue', '');
}

function equipOrderWhere(){
	var equipOrderId = $("#equipOrder_Id").textbox('getValue');
	var businessName = $("#equipOrder_businessName").textbox('getValue');
	var equipOrderOrderName = $("#equipOrder_eorderName").textbox('getValue');
	var equipOrderOrderState = $("#equipOrder_eorderState").combobox('getValue');
	$("#equipOrder_list_dg").datagrid(
			'load',
			'get_EquipOrderWhere?equipOrderId=' + equipOrderId + '&businessName='
					+ businessName + '&eorderName=' + equipOrderOrderName+'&eorderState='+equipOrderOrderState);
	$("#equipOrder_Id").textbox('setValue','');
	$("#equipOrder_businessName").textbox('setValue','');
	$("#equipOrder_eorderName").textbox('setValue','');
	$("#equipOrder_eorderState").combobox('setValue','');
}

function equipBuyOrderWhere(){
	var equipOrderId = $("#equipBuyOrder_Id").textbox('getValue');
	var businessName = $("#equipBuyOrder_businessName").textbox('getValue');
	var equipOrderOrderName = $("#equipBuyOrder_eorderName").textbox('getValue');
	
	$("#BuyEplanOrder_list_tabs").datagrid(
			'load',
			'get_BuyOrderWhere?equipOrderId=' + equipOrderId + '&businessName='
					+ businessName + '&eorderName=' + equipOrderOrderName);
	$("#equipBuyOrder_Id").textbox('setValue','');
	$("#equipBuyOrder_businessName").textbox('setValue','');
	$("#equipBuyOrder_eorderName").textbox('setValue','');
}

function equipReturnWhere(){
	var businessName = $("#equipReturn_businessName").textbox('getValue');
	$("#unableESO_list_dg").datagrid(
			'load',
			'get_unableESOlistWhere?businessName=' + businessName);
	$("#equipReturn_businessName").textbox('setValue','');
	
}

function equipDeliveryWhere(){
	var equipName = $("#equipDelivery_Name").textbox('getValue');
	$("#ableESO_list_dg").datagrid(
			'load',
			'get_ableESOlistWhere?equipName=' + equipName);
	$("#equipDelivery_Name").textbox('setValue','');
	
}
var orderListButton= function(value, row, index) {	
	var btn1 = "<input onclick='orderListPrint(" +index
		+ ")' class='plan_in_btn' type='button' value='查看'>";
	var btn2 = "<input onclick='orderListOut(" +index
		+ ")' class='plan_in_btn' type='button' value='销毁'>";
	
	return  btn1 ;
}
var orderListPrint= function Onprint(index) {
	$("#eplan_order_detail").window('open');
	$("#equipOrder_list_dg").datagrid('selectRow',index);
	var row =$("#equipOrder_list_dg").datagrid('getSelected');
	var eorderId=row.eorderId;
	var eorderName= row.eorderName;
	var eopPhone = row.eopPhone;
	var eorderBdate = row.eorderBdate;
	var eorderEdate = row.eorderEdate;
	$("#print_eorderId").val(eorderId);
	$("#print_eorderName").val(eorderName);
	$("#print_eopPhone").val(eopPhone);
	$("#print_eorderBdate").val(eorderBdate);
	$("#print_eorderEdate").val(eorderEdate);
	//清空表格
	$("#tab_order_header  tr").html("");
	var header="";
	header= "<tr><td align='center'>" + '采购员：'+ eorderName+"</td>" +
				"<td align='center'>" + '电话：'+ eopPhone +"</td>" +
				"<td align='center'>" + '订单号：'+ eorderId + "</td>" +
			"/<tr><tr>"+
				"<td align='center'>" + '采购日期：'+ eorderBdate+ "</td>" +
				"<td align='center'>" + '到货日期：'+ eorderEdate+ "</td>" +
			"</tr>";
	$("#tab_order_header").append(header);
	//清空表格
	$("#print_order_details  tr:not(:first)").html("");

		$.ajax({
		url : "get_EplanOneDetailAll?eplan_id="+row.equipPlan.eplanId, // url地址
		type : "post",
		success : function(result) {
			if (result != "" && result != undefined) {
				/*var data = JSON.parse(result); // 所以这里转了一不json
												// 如果你返回的直接是json就不用转了直接操作result*/	
				 var obj =  eval('(' + result + ')'); //由JSON字符串转换为JSON对象
				var rows=obj.rows;
			var tempHtml = "";
				for (var i = 0; i < rows.length; i++) {
					tempHtml += "<tr><td align='center'>" + rows[i].edetailName3 + "</td>" +
									"<td align='center'>" + rows[i].edetailNum + "</td>" +
									"<td align='center'>" + rows[i].edetailUnit + "</td>" +
									"<td align='center'>" + rows[i].edetailType + "</td>" +
							"</tr>";
				}
				$("#print_order_details").append(tempHtml); // 添加你拼接好的html到table里
			}
		},
		error : function(err) {
			
		}
	});
}
function print(){
	var newWindow=window.open("打印窗口","_blank");
	var docStr = $("#orderDetsils_print").html();
	newWindow.document.write(docStr);
	newWindow.document.close();
	newWindow.print();
	newWindow.close();
}
var orderListOut = function (index){
	$("#equipOrder_list_dg").datagrid('selectRow',index);
	var row =$("#equipOrder_list_dg").datagrid('getSelected');
	
	$.messager.confirm("销毁","确认销毁！",function (v){
		if(v){
			$.post("set_OrderDelete",{
				eplanOrder_Id:row.eorderId
			},function(s){
				$("#equipOrder_list_dg").datagrid('load');
			});
		}
	});
	
}
